﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MotorcycleStore.Repository;
using MotorcycleStore.DomainModel;

namespace MotorcycleStoreData.EF
{
	public class CategoryRepository : ICategoryRepository
	{
		MotorcycleStoreContext context;

		public CategoryRepository(string connectionString)
		{
			context = new MotorcycleStoreContext(connectionString);
		}

		public IQueryable<Category> Categories
		{
			get { return context.Categories; }
		}

		public void Add(Category category)
		{
			context.Categories.AddObject(category);
		}

		public void Delete(int categoryId)
		{
			var category = context.Categories.Single(c => c.Id == categoryId);
			context.Categories.DeleteObject(category);
		}

		public void Save()
		{
			context.SaveChanges();
		}
	}
}
